#define _CRT_SECURE_NO_WARNINGS
#include "ObjectPool.hpp"
#include "ConcurrentAlloc.hpp"

void Alloc1()
{
	std::vector<void*> v;
	for (int i = 0; i < 7; i++)
	{
		void* ptr = ConcurrentAlloc(6);
		v.push_back(ptr);
	}
	for (auto e : v)
	{
		ConcurrentFree(e);
	}
}

void Alloc2()
{
	std::vector<void*> v;
	for (int i = 0; i < 7; i++)
	{
		void* ptr = ConcurrentAlloc(6);
		v.push_back(ptr);
	}
	for (auto e : v)
	{
		ConcurrentFree(e);
	}
}
void TLSTest()
{
	thread t1(Alloc1);

	thread t2(Alloc2);
	t1.join();
	t2.join();
}
void TestConcurrentPool()
{
	void* p1 = ConcurrentAlloc(7);
	void* p2 = ConcurrentAlloc(1);
	void* p3 = ConcurrentAlloc(3);
	void* p4 = ConcurrentAlloc(4);
	void* p5 = ConcurrentAlloc(8);

	void* p6 = ConcurrentAlloc(8);
	void* p7 = ConcurrentAlloc(8);
	cout << p1 << endl;
	cout << p2 << endl;
	cout << p3 << endl;
	cout << p4 << endl;
	cout << p5 << endl;

	ConcurrentFree(p1);
	ConcurrentFree(p2);
	ConcurrentFree(p3);
	ConcurrentFree(p4);
	ConcurrentFree(p5);	
	ConcurrentFree(p6);	
	ConcurrentFree(p7);

}

void TestConcurrentAlloc2()
{
	for (int i = 0; i < 1024; i++)
	{
		void* p1 = ConcurrentAlloc(6);
		cout << p1 << endl;
	}
	void* p2 = ConcurrentAlloc(6);
	cout << p2 << endl;
}

void BigAlloc()
{
	void* p1 = ConcurrentAlloc(257 * 1024);
	ConcurrentFree(p1);
	void* p2 = ConcurrentAlloc(257 * 1024);
	ConcurrentFree(p2);
}
//int main()
//{
//	//TestObjectPool();
//	//TestConcurrentPool();
//	//TestConcurrentAlloc2();
//	TestConcurrentPool();
//	//TLSTest();
//	BigAlloc();
//	std::cout << sizeof(PAGE_ID) << std::endl;
//	return 0;
//}